package fr.ifsic.film.client.ui;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Grid;
import com.google.gwt.user.client.ui.VerticalPanel;

import fr.ifsic.film.client.FilmProject;

public class Accueil extends VerticalPanel {
	final Button listPerson = new Button("Liste des personnes");
	final Button newPerson = new Button("Nouvelle personne");
	final Button listActor = new Button("Liste des acteurs");
	final Button newActor = new Button("Nouvel acteur");
	final Button listMovie = new Button("Liste des films");
	final Button newMovie = new Button("Nouveau film");
	final Button listStar = new Button("Liste des vedettes");
	final Button newStar = new Button("Nouvelle vedette");
	private final Grid grid = new Grid(4, 2);

	public Accueil() {
		add(grid);
		grid.setWidget(0, 0, listPerson);
		listPerson.setWidth("100%");
		grid.setWidget(0, 1, newPerson);
		newPerson.setWidth("100%");
		grid.setWidget(1, 0, listActor);
		listActor.setWidth("100%");
		grid.setWidget(1, 1, newActor);
		newActor.setWidth("100%");
		grid.setWidget(2, 0, listMovie);
		listMovie.setWidth("100%");
		grid.setWidget(2, 1, newMovie);
		newMovie.setWidth("100%");
		grid.setWidget(3, 0, listStar);
		listStar.setWidth("100%");
		grid.setWidget(3, 1, newStar);
		newStar.setWidth("100%");

		listPerson.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				((ListeType) FilmProject.lp).refresh();
				FilmProject.changePage(FilmProject.lp);
			}
		});

		listActor.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				((ListeType) FilmProject.la).refresh();
				FilmProject.changePage(FilmProject.la);
			}
		});

		listMovie.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				((ListeType) FilmProject.lf).refresh();
				FilmProject.changePage(FilmProject.lf);
			}
		});

		listStar.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				((ListeType) FilmProject.lv).refresh();
				FilmProject.changePage(FilmProject.lv);
			}
		});

		newPerson.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				FilmProject.changePage(FilmProject.np);
			}
		});

		newActor.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				((NouvelActeur) FilmProject.na).refreshListe();
				FilmProject.changePage(FilmProject.na);
			}
		});

		newMovie.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				((NouveauFilm) FilmProject.nf).refreshListe();
				FilmProject.changePage(FilmProject.nf);
			}
		});

		newStar.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				((NouvelleVedette) FilmProject.nv).refreshListe();
				FilmProject.changePage(FilmProject.nv);
			}
		});

	}

}